<template>
	<view>
		<uni-nav-bar title="团惠包" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
		<view class="package" style="padding: 10rpx 20rpx 0px;">
			<uni-segmented-control
			  :current="current"
			  :values="items"
			  @clickItem="onClickItem" 
			  styleType="text"
			  activeColor="#1D92FF">
			</uni-segmented-control>
		</view>
		<dragImg @btnClick="navTo('groupBenefits/groupEditor')" :img_sub="AddTeam4" v-if="Useridentity=='1'"></dragImg>
		<!-- 列表 -->
		<scroll-view
		  scroll-y="true"
		  enable-back-to-top
		  @scrolltolower="loadMore"
		  class="scroll-box"
		  :style="{ height: pageHeight + 'px' }"
		>
			<groupPackage :orderList="orderLists"></groupPackage>
			<view class="column fillings" v-if="orderLists&&orderLists.length<1" style="height:80vh">
			  <image :src="Empty"></image>
			  <text >暂无团惠包订单</text>
			</view>
		</scroll-view>
	</view>
</template>

<script setup lang="ts">
	import { navBack,navTo} from '@/utils/navigator';
	import groupPackage from '@c/groupBenefits/GroupPackage.vue';
	import { onLoad } from '@dcloudio/uni-app';
	import dragImg from '@c/drag-button/drag-img.vue';
	import { Empty } from '@/utils/Static';
	import { errorToast} from '@/utils/prompt';
	import { AddTeam4 } from '@/utils/Static';
	import { toPublish } from '@mqtt';
	import { ref} from 'vue'; 
	import {myorderTeam} from '@/gql/group';
	import { getDriverID } from '@/stores/driverID';
	const driver_id = getDriverID();
	const Useridentity=uni.getStorageSync('Useridentity')
	const current=ref(0)
	const items= ['我创建的', '我购买的','我分享的']
	const isLoading = ref(false);
	const lastPage = ref(1);
	const currentPage = ref(1);
	const orderLists=ref([])
	const stateType=ref("create")
	const pageHeight = ref();
	onLoad((pearm)=>{
		uni.getSystemInfo({
		  success: function(res) {
		    pageHeight.value = (res.windowHeight - 65).toString();
		  },
		});
	})
	init();
	function init() {
	  const payload = {
	    query: myorderTeam,
	    variables: {
	      driver_id,
		  page: currentPage.value,
		  type:stateType.value,
	    },
	  };
	  toPublish(
	    'ql/store/getBaoList',
	    payload,
	    (obj: any) => { 
	      const { bao_list } = obj.data;
	      isLoading.value = false;
	      orderLists.value = [...orderLists.value, ...bao_list.list];
	      lastPage.value = bao_list.lastpage;
	    },
	    () => {
	      errorToast('通讯异常');
	    },
	  );
	}
	/**
	 * 加载更多
	 */
	function loadMore() {
	  if (currentPage.value < lastPage.value) {
	    currentPage.value++;
	    init();
	  }
	}
	function onClickItem(e){
		console.log(e.currentIndex)
		current.value=e.currentIndex
		stateType.value=e.currentIndex=='0'?'create':e.currentIndex=='1'?'buy':e.currentIndex=='2'?'share':''
		orderLists.value=[]
		currentPage.value=1
		init();
	}
</script>

<style scoped lang="less">
	.fillings {
		image {
			width: 350rpx;
			height: 300rpx;
		}
	
		text {
			font-size: 32rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #666;
			margin-top: 50rpx;
		}
	}
</style>